package com.shuyun.xxx.guava.algorithm;

import java.io.*;

/**
 * Created by goodb on 2017/5/8.
 * 打印效果
 * 12   123
 * 43   894
 *       765
 */
public class Demo {
    static int N = 0;

    public static int Helix(int x, int y) {
        if ((x == 1) && (y == 1)) return 1;
        if ((x - y >= 1) && (x + y <= N)) return (1 + Helix(x + 1, y));
        if ((x - y >= 1) && (x + y > N)) return (1 + Helix(x, y + 1));
        if ((x - y < 1) && (x + y <= N + 1)) return (1 + Helix(x, y - 1));
        if ((x - y < 1) && (x + y) > N + 1) return (1 + Helix(x - 1, y));
        else return 0;
    }
    public static void main(String[] args) {
        N = 3;
        for (int i = 1; i <= N; i++) {
            for (int j = 1; j <= N; j++)
                System.out.print(Helix(i, j));
            System.out.println("");
        }
    }

    public static String query(String query, String text){
        String[] strs = text.split("-");
        if(strs != null && strs.length > 0){
            for(String str : strs){
                if(query.equals(str)){
                    return str;
                }
            }
        }
        return null;
    }

    public static void readToBuffer(StringBuffer buffer, String filePath) throws IOException {
        InputStream is = new FileInputStream(filePath);
        String line;
        BufferedReader reader = new BufferedReader(new InputStreamReader(is));
        line = reader.readLine();
        while (line != null) {
            buffer.append(line);
            buffer.append("\n");
            line = reader.readLine();
        }
        reader.close();
        is.close();
    }

    public static String readFile(String filePath) throws IOException {
        StringBuffer sb = new StringBuffer();
        readToBuffer(sb, filePath);
        return sb.toString();
    }
}
